<template>
	<view class="rh-input-container">
		<view :class="['input-item', type == 'textarea' && 'textarea-item']">
			<view class="input-label">
				<slot name="label-icon"></slot>
				<text class="label-txt">{{label}}</text>
			</view>
			<view class="input-content ellipsis-1" v-if="type != 'textarea'">
				<slot name="bicon"></slot>
				<u--input
						v-model="emitValue" :inputAlign="inputAlign" fontSize="32rpx"
						disabledColor="#ffffff" @change="change" @blur="blur"
						:placeholder="placeholder" :disabled="disabled"
						border="none"
						:password="password"
				></u--input>
				<slot name="icon"></slot>
			</view>
			<view class="input-content" v-else>
				<textarea cols="30" rows="10" :maxlength="maxlength" v-model="emitValue" :placeholder="placeholder" 
				placeholder-style="color: #aaa" class="textarea" @input="change" @blur="blur"></textarea>
				<view class="show-length">{{emitValue.length || '0'}}/{{maxlength}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			password:{
				type:Boolean,
				default: () => {return false}
			},
			inputAlign:{
				type:String,
				default: () => {return 'right'}
			},
			label: String,
			value: [String, Number],
			type: {
				type: String,
				default: () => 'text'
			},
			maxlength: {
				type: String,
				default: () => '140'
			},
			placeholder: {
				type: String,
				default: () => {return '请输入'}
			},
			disabled: {
				type: Boolean,
				default: () => {return false}
			}
		},
		watch: {
			value(val){
				this.emitValue = val || ''
			},
		},
		data() {
			return {
				emitValue: this.value || '',
				boo: {
					show: true
				},
			};
		},
		methods: {
			change(e){
				let _self = this
				_self.$emit('input', _self.emitValue)
			},
			click(){
				let _self = this
				_self.$emit('click')
			},
			blur(e){
				let _self = this
				_self.$emit('blur', e)
			},
		}
	}
</script>

<style scoped lang="scss">
	.rh-input-container{
		width: 100%;
	}
	.input-item{
		display: flex;
		justify-content: space-between;
		align-items: center;
		&.textarea-item{
			flex-direction: column;
			align-items: flex-start;
			.input-label{
				margin-bottom: 20rpx;
			}
			.input-content{
				margin-top: 20rpx;
				margin-left: 20rpx;
				background-color: #F7F8F9;
				position: relative;
				border-radius: 16rpx;
				margin: auto;
				padding: 20rpx;
				width: 100%;
				.textarea{
					width: inherit;
					height: 100rpx;
					font-size: 32rpx;
				}
				.show-length{
					position: absolute;
					font-size: 32rpx;
					color: #ccc;
					bottom: 15rpx;
					right: 20rpx;
				}
			}
		}
		.input-label{
			display: flex;
			align-items: center;
			.label-txt{
				font-size: 32rpx;
				color: #666;
			}
		}
		.input-content{
			flex: 1;
			// width: 622rpx;
			display: flex;
			align-items: center;
		}
	}
</style>
